package com.zyh.day04.sql

import org.apache.spark.sql.SparkSession

object JoinTest {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession.builder()
      .appName("where")
      .master("local[*]")
      .getOrCreate()

    import spark.implicits._
    val stuDF = List((1, "张三", 1001), (2, "李四", 1001), (3, "王五", 1002), (4, "赵六", 1003))
      .toDF("id","name","cid")

    val classDF = List((1001, "Java班"), (1002, "UI班"))
      .toDF("cid","cname")

    stuDF.createOrReplaceTempView("t_student")
    classDF.createOrReplaceTempView("t_class")

    val sql =
      """
select * from t_student t1 left join t_class t2 on t1.cid = t2.cid
"""

    spark.sql(sql).show()
    spark.close()
  }
}
